<template>
  <div>
      <input type="text" v-model="username"/>
      <input type="password" v-model="password"/>
      <input type="submit" value="登陆" v-on:click="login"/>
    <br>
    <span v-if="!!exceptionMessage">{{exceptionMessage}}</span>
  </div>
</template>

<script>
import global from '../global'

export default {
  name: 'LoginPage',
  data () {
    return {
      username: '',
      password: '',
      exceptionMessage: ''
    }
  },
  methods: {
    login: function () {
      this.$axios.post('web_api/login', {
        synch_req: true,
        data: {
          username: this.username,
          password: this.password
        }
      }).then((res) => {
        console.log(res)
        if (res.data.data.exceptionMessage) {
          this.exceptionMessage = res.data.data.exceptionMessage
          return
        }
        global.login(res.data.data.session_id, res.data.data.session_vc)
      }).catch((res) => {
        console.log(res)
      })
    }
  }
}
</script>

<style scoped>

</style>
